package com.ruibang.glass.sale.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.sale.domain.req.GSaleCustomerManReq;
import com.ruibang.glass.sale.dto.SelectDTO;
import com.ruibang.glass.sale.entity.GSaleCustomerManagement;
import com.ruibang.glass.sale.mapper.GSaleCustomerManagementMapper;
import com.ruibang.glass.sale.service.GSaleCustomerManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


@Slf4j
@Service
public class GSaleCustomerManagementServiceImpl extends ServiceImpl<GSaleCustomerManagementMapper, GSaleCustomerManagement> implements GSaleCustomerManagementService {


    @Override
    public IPage<GSaleCustomerManagement> getPage(GSaleCustomerManReq gSaleCustomerManReq) {
        return baseMapper.getPage(new Page<GSaleCustomerManagement>(gSaleCustomerManReq.getPageNo(), gSaleCustomerManReq.getPageSize()), gSaleCustomerManReq);
    }

    @Override
    public void updateOrAdd(GSaleCustomerManagement gSaleCustomerManagement) {
        if (StringUtils.isEmpty(gSaleCustomerManagement.getId())) {
            baseMapper.insert(gSaleCustomerManagement);
            return;
        }
        baseMapper.updateById(gSaleCustomerManagement);
    }

    @Override
    public List<SelectDTO> getSaleCustomerManagement() {
        List<SelectDTO> selectDTOList = new ArrayList<>();
        List<GSaleCustomerManagement> gSaleCustomerManagements = baseMapper.selectList();
        for (GSaleCustomerManagement gSaleCustomerManagement : gSaleCustomerManagements) {
            SelectDTO selectDTO = new SelectDTO();
            selectDTO.setLabel(gSaleCustomerManagement.getCustomerName());
            selectDTO.setValue(gSaleCustomerManagement.getId());
            selectDTOList.add(selectDTO);
        }
        return selectDTOList;
    }


}
